﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        登录名称：<input id="userName" col="UserName" type="text" />
                    </li>
                    <li>
                        操作方法：<input id="executeUrl" col="ExecuteUrl" type="text" />
                    </li>
                    <li>
                        操作状态：<span id="logStatus" col="LogStatus"></span>
                    </li>
                    <li class="select-time">
                        <label>操作时间： </label>
                        <input id="startTime" col="StartTime" type="text" class="time-input" placeholder="开始时间" />
                        <span>-</span>
                        <input id="endTime" col="EndTime" type="text" class="time-input" placeholder="结束时间" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm" id="toolbar">
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
            <a id="btnDelete" class="btn btn-danger" onclick="removeAllForm()"><i class="fa fa-trash"></i> 清空</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();

        $("#logStatus").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(OperateStatusEnum).EnumToDictionaryString())) });

        laydate.render({ elem: '#startTime', format: 'yyyy-MM-dd' });
        laydate.render({ elem: '#endTime', format: 'yyyy-MM-dd' });
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/SystemManage/LogOperate/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'UserName', title: '登录名称' },
                { field: 'DepartmentName', title: '部门名称' },
                { field: 'IpAddress', title: 'Ip地址' },
                { field: 'ExecuteUrl', title: '操作方法' },
                { field: 'ExecuteTime', title: '耗时（ms）' },
                {
                    field: 'LogStatus', title: '操作状态', align: 'center',
                    formatter: function (value, row, index) {
                        if (value == "@OperateStatusEnum.Success.ParseToInt()") {
                            return '<span class="badge badge-primary">' + "@OperateStatusEnum.Success.GetDescription()" + '</span>';
                        } else {
                            return '<span class="badge badge-warning">' + "@OperateStatusEnum.Fail.GetDescription()" + '</span>';
                        }
                    }
                },
                {
                    field: 'BaseCreateTime', title: '操作时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="#" onclick="showDetailForm(\'' + row.Id + '\')"><i class="fa fa-search"></i>详细</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $("#searchDiv").getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function deleteForm() {
        var selectedRow = $("#gridTable").bootstrapTable("getSelections");
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm("确认要删除选中的" + selectedRow.length + "条数据吗？", function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/SystemManage/LogOperate/DeleteFormJson")' + '?ids=' + ids,
                    type: "post",
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }

    function removeAllForm() {
        ys.confirm("确认要清空表吗？", function () {
            ys.ajax({
                url: '@Url.Content("~/SystemManage/LogOperate/RemoveAllFormJson")',
                type: "post",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        searchGrid();
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        });
    }

    function showDetailForm(id) {
        ys.openDialog({
            title: "操作日志详细",
            content: '@Url.Content("~/SystemManage/LogOperate/LogOperateDetail")' + '?id=' + id
        });
    }
</script>
